﻿@using RiverCruise.Helpers
@model RiverCruise.Models.Company.CompanyDetailViewModel

@{
    ViewBag.Title = "Company Detail";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="container-fluid">
    @if (Roles.IsUserInRole(RoleHelper.Edit))
    {
        <div class="row">

            <div class="dropdown margin">
                <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
                    <span class="glyphicon glyphicon-cog"></span>
                    Manage
                    <span class="caret"></span>
                </button>
                <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                    <li>
                        <a href="@Url.Action("Edit", "CompanyManagement", new {Id = Model.Id})">
                            <span class="glyphicon glyphicon-edit"></span>
                            Edit
                        </a>
                    </li>
                    <li role="presentation">
                        <a href="@Url.Action("AddShip", "ShipManagement", new {CompanyId = Model.Id })" class="">
                            <span class="glyphicon glyphicon glyphicon-plus"></span>
                            Add Ship
                        </a>
                    </li>
                    
                    <li role="presentation">
                        <a class="triggerModal" data-rc-modalaction="DeleteGet" data-rc-modalcontroller="CompanyManagement" href="#" data-rc-name="@Model.Name" data-rc-id="@Model.Id">
                            <span class="glyphicon glyphicon-trash"></span>
                            Delete
                        </a>
                    </li>
                </ul>
            </div>
        </div>
        
        <span class="clearfix"></span>
    }
    
    @if (!ViewData.ModelState.IsValid)
    {
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <div class="bs-callout bs-callout-danger text-danger">
                    @Html.ValidationSummary()
                </div>  
            </div>
        </div>
    }

    <ul class="nav nav-tabs">
        <li role="presentation" class="active"><a href="#" id="DetailLink">Detail</a></li>
        <li role="presentation"><a href="#" id="historyLink">History</a></li>
    </ul>
    
    <div id="DetailTabContent">
        <h2>@Model.Name</h2>

        <div class="container-fluid">
            @if (!string.IsNullOrEmpty(Model.Website))
            {
                <a href="@Model.Website" target="_blank">@Model.Website</a>
            }
            <br/>
            <h4>Detail</h4>
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-6">
                        @Html.LabelFor(model => model.Ships):
                        @Model.Ships.Count()
                        <br />
                        @Html.LabelFor(model => model.Reports):
                        @Model.Reports
                        <br />
                        @Html.LabelFor(model => model.ReportsPerShip):
                        @Model.ReportsPerShip
                        <br />
                        @Html.LabelFor(model => model.ShipsVisited):
                        @Model.ShipsVisited
                        <br />
                        @Html.LabelFor(model => model.PercentageShipsVisited):
                        @Model.PercentageShipsVisited
                    </div>
                    <div class="col-md-6">
                        @Html.LabelFor(model => model.NauticalCrewString):
                        @Model.NauticalCrewString
                        <br />
                        @Html.LabelFor(model => model.HotelStaffString):
                        @Model.HotelStaffString
                        <br />
                        @Html.LabelFor(model => model.TotalCrew):
                        @Model.TotalCrew
                    </div>
                </div>
            </div>
            <br />
            <h4>
                <span class="h4content">
                    Ships
                </span>
            </h4>
            <div class="container-fluid">
                <hr />
                @foreach (var ship in @Model.Ships)
                {
                    <div class="clearfix">
                        <div class="pull-right">
                            <label>Reports: </label>@ship.Reports<br />
                            <label>Last report:</label> @ship.LastReport
                        </div>
                        <div>
                            @Html.ActionLink(ship.Name, "Detail", "Home", new { ship.Id }, new { @class="tile-blue"})
                        </div>
                    </div>
                    <hr />
                }
            </div>
        </div>
    </div>
    <div id="historyPlaceHolder">
        <div class="text-center">
            <img src="~/Content/images/loading5.gif" />
        </div>
    </div>
</div>
<script>
    $(document).ready(function() {
        $('#historyPlaceHolder').hide();
    });
    
    $("#historyLink").click(function (e) {
        e.preventDefault();

        $("#DetailTabContent").hide();
        $("#historyPlaceHolder").fadeIn();
        $("#historyLink").parent().parent().children().removeClass("active");
        $("#historyLink").parent().addClass("active");

        var options = {
            url: "@Url.Action("CompanyHistory", "Company", new { Id = Model.Id}, null)",
            type: "get"
        };

        $.ajax(options).done(function (data) {
            var target = "#historyPlaceHolder";
            $(target).html(data);
        });

        return null;
    });

    $("#DetailLink").click(function (e) {
        e.preventDefault();
        $("#historyPlaceHolder").hide();
        $("#DetailTabContent").fadeIn();
        $("#DetailLink").parent().parent().children().removeClass("active");
        $("#DetailLink").parent().addClass("active");
        return null;
    });
</script>